//
//  M1RecentFriendCell.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/20.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1RecentFriendCell.h"

@implementation M1RecentFriendCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self m1_createUI];
    }
    return self;
}

- (void) m1_createUI{
    
    self.m1_coverImage = [[UIImageView alloc] init];
    _m1_coverImage.image = LOAD_LOCAL_IMG(@"bgView");
    _m1_coverImage.contentMode = UIViewContentModeScaleAspectFill;
    _m1_coverImage.clipsToBounds = YES;
    [self.contentView addSubview:_m1_coverImage];
    
    _m1_coverImage.layer.cornerRadius = 55 / 2;
    _m1_coverImage.layer.masksToBounds = YES;
    
    [_m1_coverImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.left.offset(20);
        make.size.mas_equalTo(CGSizeMake(55, 55));
    }];
    
    self.m1_name = [[UILabel alloc]init];
    _m1_name.text = @"Cedar";
    _m1_name.textColor = m1_color(0x333333);
    _m1_name.font = m1_font(16);
    [self.contentView addSubview:_m1_name];
    
    self.m1_time = [[UILabel alloc]init];
    _m1_time.text = @"07-08";
    _m1_time.textColor = m1_color(0x999999);
    _m1_time.font = m1_font(14);
    [self.contentView addSubview:_m1_time];
    
    [_m1_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.m1_coverImage.mas_right).offset(17);
        make.right.equalTo(self.m1_time.mas_left).offset(-15);
        make.top.offset(14);
    }];
    
    [_m1_time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-20);
        make.top.offset(20);
    }];
    
    self.m1_age = [[UILabel alloc]init];
    _m1_age.backgroundColor = m1_color(0xFCF0F0);
    _m1_age.text = @"25";
    _m1_age.textColor = m1_color(0xFF666B);
    _m1_age.textAlignment = NSTextAlignmentCenter;
    _m1_age.font = m1_font(12);
    [self.contentView addSubview:_m1_age];
    
    self.m1_tall = [[UILabel alloc]init];
    _m1_tall.backgroundColor = m1_color(0xFCF0F0);
    _m1_tall.text = @"168cm";
    _m1_tall.textColor = m1_color(0xFF666B);
    _m1_tall.textAlignment = NSTextAlignmentCenter;
    _m1_tall.font = m1_font(12);
    [self.contentView addSubview:_m1_tall];
    
    self.m1_location = [[UILabel alloc]init];
    _m1_location.backgroundColor = m1_color(0xFCF0F0);
    _m1_location.text = @"杭州";
    _m1_location.textColor = m1_color(0xFF666B);
    _m1_location.textAlignment = NSTextAlignmentCenter;
    _m1_location.font = m1_font(12);
    [self.contentView addSubview:_m1_location];
    
    self.m1_age.layer.cornerRadius = 28 / 2;
    self.m1_age.layer.masksToBounds = YES;
    
    self.m1_tall.layer.cornerRadius = 28 / 2;
    self.m1_tall.layer.masksToBounds = YES;
    
    self.m1_location.layer.cornerRadius = 28 / 2;
    self.m1_location.layer.masksToBounds = YES;
    
    self.m1_line = [[UIView alloc] init];
    _m1_line.backgroundColor = m1_color(0xCCCCCC);
    [self.contentView addSubview:_m1_line];
    
    [_m1_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(19);
        make.right.offset(-20);
        make.bottom.offset(0);
        make.height.offset(0.5);
    }];
    
    [self.m1_age sizeToFit];
    
    [_m1_age mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.m1_coverImage.mas_right).offset(15);
        make.top.equalTo(self.m1_name.mas_bottom).offset(4);
        make.size.mas_equalTo(CGSizeMake(self.m1_age.frame.size.width + 20, 28));
    }];
    
    [self.m1_tall sizeToFit];
    
    [_m1_tall mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.m1_age.mas_right).offset(5);
        make.centerY.equalTo(self.m1_age.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(self.m1_tall.frame.size.width + 20, 28));
    }];
    
    [self.m1_location sizeToFit];
    
    [_m1_location mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.m1_tall.mas_right).offset(5);
        make.centerY.equalTo(self.m1_age.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(self.m1_location.frame.size.width + 20, 28));
        make.height.offset(28);
    }];
    
}

- (void)setM1_user:(M1User *)m1_user
{
    [self.m1_coverImage sd_setImageWithURL:[NSURL URLWithString:m1_user.basic.avatar.img.url] placeholderImage:[UIImage imageNamed:@"bgView"]];
    self.m1_name.text = m1_user.basic.name;
    self.m1_age.text = [NSString stringWithFormat:@"%@岁",m1_user.basic.age];
    self.m1_tall.text = [NSString stringWithFormat:@"%@cm",m1_user.basic.high];
    self.m1_location.text = [m1_user.basic.abode rangeOfString:@"-"].location == NSNotFound ? m1_user.basic.abode : [m1_user.basic.abode componentsSeparatedByString:@"-"][1];
    self.m1_time.text = [M1Founction m1_dateFormTimeStamp:[m1_user.basic.create_time integerValue]];
    
    self.m1_tall.hidden = !m1_user.basic.high;
    self.m1_location.hidden = !m1_user.basic.abode;
    [self.m1_location sizeToFit];
    [_m1_location mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.m1_tall.mas_right).offset(5);
        make.centerY.equalTo(self.m1_age.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(self.m1_location.frame.size.width + 20, 28));
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
